<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="/bootstrap.css">
    <style>
        .container {
            width: 500px;
            margin: 20px auto;
        }

        .add {
            width: 100%;
            height: 40px;
            font-size: 35px;
            text-align: center;
            line-height: 40px;

        }

        body {
            background: #ccc;
        }
        .mesg{
            width:100%;
            text-align:center;
            line-height:100%;
            font-size:35px; 
        }
        a:hover{
            text-decoration: none;
            color:#fff;
        }
        a{
            color:#fff;
            font-size:16px;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <template id="txt">
        <div class="container">
            <el-form ref="form" :model="users" label-width="80px">
                <el-form-item>
                   <div slot-scope="scopre" class="mesg">信息修改</div>
                </el-form-item>
                <el-form-item label="用户名">
                    <el-input v-model="users.username"></el-input>
                </el-form-item>
                <el-form-item label="年龄">
                    <el-input v-model="users.age"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="resource">
                    <el-radio-group v-model="users.sex">
                        <el-radio label="boy"></el-radio>
                        <el-radio label="girl"></el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="手机号">
                    <el-input v-model="users.phone"></el-input>
                </el-form-item>
                <el-form-item>
                    <div slot-scope="scope">
                        <el-button @click="save()" type="success">save</el-button>
                        <el-button type="warning"><a href="/element.html">返回</a></el-button>
                    </div>
                </el-form-item>
            </el-form>
        </div>
    </template>
</body>
<script src="/vue.min.js"></script>
<script src="/jquery.min.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js "></script>
<script>
    var vm = new Vue({
        el: '#app',
        template: '#txt',
        data: function () {
            return {
                users: {
                    username: '',
                    age: '',
                    sex: '',
                    phone: '',
                    id: location.hash.replace('#', '')
                },

            }
        },


        created: function () {
            this.find()
        },
        methods: {
            find: function () {
                var _this = this
                $.get('/users/find', { id: this.users.id }).done(function (result) {
                    console.log(result)
                    console.log(_this.users.id)
                    console.log(result.username)
                    _this.users.username = result.username
                    _this.users.age = result.age
                    _this.users.sex = result.sex
                    _this.users.phone = result.phone
                })
            },
            save: function () {
                $.post('/users/edit', this.users).done(function () {
                    location.href = '/element.html'
                })
            }

        }
    })
</script>

</html>